#!/bin/bash
## load modules 
module load gcc/4.8.2 gdc bwa/0.7.17 java/1.8.0_73 sambamba/0.6.8
##number of processors used per job
proc=20
##Defining all the paths 
reference="reference.fasta"
input="/path/to/seqprep/output"
out="/path/to/output"

#name of the individual that will be mapped (Filename must start with these Characters)
ind=$LSB_JOBINDEX
name="DF$ind"
short=$name

#BWA:
#forward and reverse:
bwa mem -t ${proc} -r 1 -M ${reference} ${input}/${name}_R1.polyg.n.fastq.gz ${input}/${name}_R2.polyg.n.fastq.gz > ${TMPDIR}/${short}_FR_n.sam
sambamba view -S ${TMPDIR}/${short}_FR_n.sam -f bam -o ${out}/${short}_FR_n.bam -t ${proc} -l 9

#merged reads
bwa mem -t ${proc} -r 1 -M ${reference} ${input}/${name}_mr.polyg.n.fastq.gz > ${TMPDIR}/${short}_M_n.sam
sambamba view -S ${TMPDIR}/${short}_M_n.sam -f bam -o ${out}/${short}_M_n.bam -t ${proc} -l 9


